import { Injectable, Inject } from '@nestjs/common';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';

@Injectable()
export class EventEmittersService {
  // 注入 event emitter
  @Inject(EventEmitter2)
  private eventEmitter: EventEmitter2;

  // 发送数据
  findAll() {
    this.eventEmitter.emit('aaa.find', {
      data: 'xxxx',
    });

    this.eventEmitter.emit('aaa.find2', {
      data: 'xxxx2',
    });
    return `This action returns all aaa`;
  }

  // 接收数据
  @OnEvent('aaa.find')
  handleFind1(data) {
    console.log(data);
    return 'test';
  }

  // 接收数据2
  @OnEvent('aaa.*')
  handleFind2(data) {
    console.log(data);
    return 'test';
  }
}
